const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

/**
 * 清理所有测试数据
 */
async function cleanTestData() {
  try {
    console.log('开始清理所有测试数据...');
    
    // 删除支付记录
    console.log('正在删除支付记录...');
    const deletedPayments = await prisma.payment.deleteMany({});
    console.log(`已删除 ${deletedPayments.count} 条支付记录`);
    
    // 删除订单项
    console.log('正在删除订单项...');
    const deletedOrderItems = await prisma.orderItem.deleteMany({});
    console.log(`已删除 ${deletedOrderItems.count} 条订单项记录`);
    
    // 删除订单
    console.log('正在删除订单...');
    const deletedOrders = await prisma.order.deleteMany({});
    console.log(`已删除 ${deletedOrders.count} 条订单记录`);
    
    // 删除班次渠道销售记录
    console.log('正在删除班次渠道销售记录...');
    const deletedShiftChannelSales = await prisma.shiftChannelSale.deleteMany({});
    console.log(`已删除 ${deletedShiftChannelSales.count} 条班次渠道销售记录`);
    
    // 删除班次支付方式记录
    console.log('正在删除班次支付方式记录...');
    const deletedShiftPayments = await prisma.shiftPayment.deleteMany({});
    console.log(`已删除 ${deletedShiftPayments.count} 条班次支付方式记录`);
    
    // 删除班次
    console.log('正在删除班次...');
    const deletedShifts = await prisma.shift.deleteMany({});
    console.log(`已删除 ${deletedShifts.count} 条班次记录`);
    
    console.log('所有测试数据已清理完成');
  } catch (error) {
    console.error('清理数据时出错:', error);
  } finally {
    await prisma.$disconnect();
  }
}

// 执行清理
cleanTestData()
  .catch(e => {
    console.error('执行脚本时出错:', e);
    process.exit(1);
  }); 